﻿//载入基础页面
{extend name="common/base" /}

//页面单独CSS
{block name="CustomCSS"}

{/block}

//页面单独JS
{block name="CustomJS"}
<script src="__STATIC__/vendors/js/validation/validation.min.js"></script>
<script src="__STATIC__/vendors/js/jquery.form/jquery.form.min.js"></script>
<script src="__STATIC__/vendors/js/noty/noty.min.js"></script>
<script type="text/javascript">
	// jquery 表单提交 
	// $("#ajaxForm").submit(function(message) { 
		
	// }); 
	$(document).ready(function () {
            $("#ajaxForm").ajaxForm({
                //定义返回JSON数据，还包括xml和script格式
                dataType: 'json',
				//在发送之前进行的操作，如果有问题，返回false即可不会进行提交
                beforeSend: function () {
                	//定义 form为当前表格
                    const form = $("#ajaxForm")
	
					//如果没有完成校验就返回false不提交
					if (form[0].checkValidity() === false){
						return false;
					}
                },
                success: function (data) {
                    //提交成功后调用
                    new Noty({
			            type: "success",
			            layout: "topRight",
			            text: "成功修改一条数据，ID为" + data,
			            progressBar: true,
			            timeout: 2500,
			            animation: {
			                open: "animated bounceInRight",
			                close: "animated bounceOutRight"
			            },
			            callbacks: {
			            	afterShow: function() {
			            		$(location).attr('href', '../../index');
			            	},
			            }
			        }).show();
                    return false;
                },
                error: function(XmlHttpRequest, textStatus, errorThrown){  
                    //提交成功后调用
                    new Noty({
			            type: "error",
			            layout: "topRight",
			            text: "数据添加失败",
			            progressBar: true,
			            timeout: 2500,
			            animation: {
			                open: "animated bounceInRight",
			                close: "animated bounceOutRight"
			            }
			        }).show();
			        return false;
                } 
            });
        });
 
</script>
{/block}

//页面显示名称
{block name="PageName"}
编辑物料报价信息
{/block}

//主页面代码
{block name="main"}
<div class="row">
    <div class="col-xl-12">
        <div class="widget has-shadow">
        	<div class="widget-header bordered no-actions d-flex align-items-center">
                <h2>编辑物料报价信息</h2>
            </div>
            <div class="widget-body">
                <form class="needs-validation" novalidate="" id="ajaxForm" action="{:url('Material/update',['id' => $data.id])}">
	                <div class="form-group row d-flex align-items-center mb-5">
	                    <label class="col-lg-3 form-control-label d-flex justify-content-lg-end">物料名称 *</label>
	                    <div class="col-lg-6">
	                        <input type="text" class="form-control" placeholder="请输入物料名称" required name="name" value="{$data.name}">
	                        <div class="invalid-feedback">
	                            请输入物料名称
	                        </div>
	                    </div>
	                </div>
	                <div class="form-group row d-flex align-items-center mb-5">
	                    <label class="col-lg-3 form-control-label d-flex justify-content-lg-end">物料单价 *</label>
	                    <div class="col-lg-6">
	                        <input type="number" class="form-control" placeholder="请输入物料单价" required name="price" step="0.10" pattern="/(^[\d]|^[1-9][\d]*)($|[\.][\d]{0,2}$)/" value="{$data.price}">
	                        <div class="invalid-feedback">
	                        	请输入物料单价
	                    	</div>
	                    </div>
	                </div>
	                <div class="form-group row d-flex align-items-center mb-5">
	                    <label class="col-lg-3 form-control-label d-flex justify-content-lg-end">物料单位 *</label>
	                    <div class="col-lg-6">
	                        <input type="text" class="form-control" placeholder="请输入物料单位" required name="unit" value="{$data.unit}">
	                        <div class="invalid-feedback">
	                        	请输入物料单位
	                    	</div>
	                    </div>
	                </div>
	                <div class="form-group row d-flex align-items-center mb-5">
                        <label class="col-lg-3 form-control-label d-flex justify-content-lg-end">供应商 *</label>
                        <div class="col-lg-6">
                            <select class="custom-select form-control form-control-sm" placeholder="请输入物料单位" required name="supply">
                            	<option value=""></option>
                            	{volist name="supply" id="supply"}
	                                <option value="{$supply}" {if $supply == $data.supply}selected{/if}>{$supply}</option>
                                {/volist}
                            </select>
                            <div class="invalid-feedback">
	                        	请选择供应商
	                    	</div>
                        </div>
                    </div>
	                <div class="text-right">
		                <button class="btn btn-shadow" type="reset" onclick="history.go(-1);">取消</button>
		                <button class="btn btn-gradient-01" type="submit">提交</button>
		            </div>
		        </form>
            </div>
        </div>
        <!-- End Export -->
    </div>
</div>
{/block}//主页面
